<?php
namespace app\api\model;

use think\Model;
use think\Db;
use think\Cache;

class InspectDistrict extends Model
{
    protected $table = 'inspect_district';

    public function getAreaAttr($val) {
        $returnval = '';
        $area = Cache::get('area');//检查缓存
        if(!$area){  
            $area = Db::table('region')->where('type','eq',3)->field('code,name,full_name')->select();
            Cache::set('area',$area);
        }
        foreach ($area as  $value) {
            if ($value['code'] == $val) {
                $returnval = $value['full_name'];
                break;
            }
        }
        return $returnval;
    }

    public function getDistrictAttr($val) {
    	$res = Db::table('inspect_district_type')->where('id', $val)->value('name');
    	return $res;
    }

    



}